package com.hrm.service.impl;

import com.hrm.dao.HrmSalaryPayMapper;
import com.hrm.dao.HrmSalaryStandardMapper;
import com.hrm.dao.HrmStaffMapper;
import com.hrm.model.HrmStaff;
import com.hrm.service.HrmStaffService;
import com.hrm.util.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("hrmStaffService")
public class HrmStaffServiceImpl implements HrmStaffService {
	@Autowired
	protected HrmStaffMapper hrmStaffMapper;
	@Autowired
	protected HrmSalaryPayMapper hrmSalaryPayMapper;

	@Override
	public PageView findEntityPageByParam(PageView pageView, Map<String, Object> param) {
		param.put("offset", pageView.getFirstResult());
		param.put("limit", pageView.getPageSize());
		pageView.setQueryResult(hrmStaffMapper.getPageNumByMap(param),
				hrmStaffMapper.getPageByMap(param));
		return pageView;
	}

	@Override
	public int updateStaffInfo(HrmStaff hrmStaff){
		return hrmStaffMapper.updateByPrimaryKeySelective(hrmStaff);
	}

	@Override
	public HrmStaff getHrmStaff(Integer id) {
		return hrmStaffMapper.selectByPrimaryKey(id);
	}

	@Override
	public void deleteStaffById(Integer id) {
		hrmSalaryPayMapper.deleteByStaffId(id);
		hrmStaffMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int addStaff(HrmStaff hrmStaff) {
		hrmStaffMapper.insertSelective(hrmStaff);
		return 1;
	}
}
